﻿namespace DotRas
{
    using System;
    using System.Runtime.InteropServices;
    using System.Security;

    [SuppressUnmanagedCodeSecurity]
    internal class SafeNativeMethods
    {
        private SafeNativeMethods()
        {
        }

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll", SetLastError=true)]
        public static extern bool AllocateLocallyUniqueId(IntPtr pLuid);
        public static int ClearConnectionStatistics(RasHandle hRasConn)
        {
            return RasClearConnectionStatistics(hRasConn);
        }

        public static int ClearLinkStatistics(RasHandle hRasConn, int subEntryId)
        {
            return RasClearLinkStatistics(hRasConn, subEntryId);
        }

        public static int EnumConnections(IntPtr lpRasConn, ref IntPtr lpCb, ref IntPtr lpcConnections)
        {
            return RasEnumConnections(lpRasConn, ref lpCb, ref lpcConnections);
        }

        public static int EnumDevices(IntPtr lpRasDevInfo, ref IntPtr lpCb, ref IntPtr lpcDevices)
        {
            return RasEnumDevices(lpRasDevInfo, ref lpCb, ref lpcDevices);
        }

        public static int GetConnectStatus(RasHandle hRasConn, IntPtr lpRasConnStatus)
        {
            return RasGetConnectStatus(hRasConn, lpRasConnStatus);
        }

        public static int GetCountryInfo(IntPtr lpRasCtryInfo, ref IntPtr lpdwSize)
        {
            return RasGetCountryInfo(lpRasCtryInfo, ref lpdwSize);
        }

        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        private static extern int RasClearConnectionStatistics(RasHandle hRasConn);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        private static extern int RasClearLinkStatistics(RasHandle hRasConn, int subEntryId);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasConnectionNotification(RasHandle hRasConn, SafeHandle hEvent, DotRas.NativeMethods.RASCN dwFlags);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasDial(IntPtr lpRasDialExtensions, string lpszPhonebook, IntPtr lpRasDialParams, DotRas.NativeMethods.RasNotifierType dwNotifierType, Delegate lpvNotifier, out RasHandle lphRasConn);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        private static extern int RasEnumConnections([In, Out] IntPtr lpRasConn, ref IntPtr lpCb, ref IntPtr lpcConnections);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        private static extern int RasEnumDevices([In, Out] IntPtr lpRasDevInfo, ref IntPtr lpCb, ref IntPtr lpcDevices);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern void RasFreeEapUserIdentity(IntPtr lpRasEapUserIdentity);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasGetConnectionStatistics(RasHandle hRasConn, IntPtr lpStatistics);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        private static extern int RasGetConnectStatus(RasHandle hRasConn, IntPtr lpRasConnStatus);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        private static extern int RasGetCountryInfo([In, Out] IntPtr lpRasCtryInfo, ref IntPtr lpdwSize);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasGetEapUserIdentity(string lpszPhonebook, string lpszEntryName, RasEapOptions dwFlags, IntPtr hwnd, ref IntPtr lpRasEapUserIdentity);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasGetErrorString(int uErrorValue, [In, Out] string lpszErrorString, int cBufSize);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasGetLinkStatistics(RasHandle hRasConn, int subEntryId, IntPtr lpRasStatistics);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasGetProjectionInfo(RasHandle hRasConn, RasProjectionType rasprojection, IntPtr lpProjection, ref IntPtr lpCb);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasGetSubEntryHandle(RasHandle hRasConn, int subEntryId, out RasHandle lphRasConn);
        [DllImport("rasapi32.dll")]
        public static extern int RasHangUp(RasHandle hRasConn);
        [DllImport("rasapi32.dll", CharSet=CharSet.Unicode)]
        public static extern int RasValidateEntryName(string lpszPhonebook, string lpszEntryName);
    }
}

